package com.qriver.auth.server.config;

import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.util.Map;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

import com.qriver.auth.common.utils.jwt.RsaKeyHelper;

/**
 * rsa的公钥和私钥的配置
 * @author ace
 * @create 2017/12/17.
 */
@Configuration
public class KeyConfiguration {
    @Value("xx1WET12^%3^(WE45")
    private String userSecret;
    @Value("x2318^^(*WRYQWR(QW&T")
    private String serviceSecret;
    private byte[] userPubKey;
    private byte[] userPriKey;
    private byte[] servicePriKey;
    private byte[] servicePubKey;
	public String getUserSecret() {
		return userSecret;
	}
	public void setUserSecret(String userSecret) {
		this.userSecret = userSecret;
	}
	public String getServiceSecret() {
		return serviceSecret;
	}
	public void setServiceSecret(String serviceSecret) {
		this.serviceSecret = serviceSecret;
	}
	public byte[] getUserPubKey() {
		Map<String, byte[]> keyMap = null;
		try {
			keyMap = RsaKeyHelper.generateKey("xx1WET12^%3^(WE45");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return keyMap.get("pub");
		//return "[B@5ce81285".getBytes();//userPubKey;
	}
	public void setUserPubKey(byte[] userPubKey) {
		this.userPubKey = userPubKey;
	}
	public byte[] getUserPriKey() {
		Map<String, byte[]> keyMap = null;
		try {
			keyMap = RsaKeyHelper.generateKey("xx1WET12^%3^(WE45");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return keyMap.get("pri");
		//return "[B@52a86356".getBytes();//userPriKey;
	}
	public void setUserPriKey(byte[] userPriKey) {
		this.userPriKey = userPriKey;
	}
	public byte[] getServicePriKey() {
		return servicePriKey;
	}
	public void setServicePriKey(byte[] servicePriKey) {
		this.servicePriKey = servicePriKey;
	}
	public byte[] getServicePubKey() {
		return servicePubKey;
	}
	public void setServicePubKey(byte[] servicePubKey) {
		this.servicePubKey = servicePubKey;
	}
    public static void main(String[] args) {
    	try {
			Map<String, byte[]> keyMap = RsaKeyHelper.generateKey("xx1WET12^%3^(WE45");
			System.out.println("pri:" + keyMap.get("pri"));
			System.out.println("pub:" + keyMap.get("pub"));
    	} catch (Exception e) {
			e.printStackTrace();
		}
       
    	
    	//keyConfiguration.setUserPriKey(keyMap.get("pri"));
       // keyConfiguration.setUserPubKey(keyMap.get("pub"));
	}
	
	 
}
